package light.head.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Formula;

/**
 * 消息接收
 * @author Jian
 */
@Entity
@Table
public class Message implements Serializable {

	private static final long serialVersionUID = -8624889739056320948L;
	
	
	private Integer code;				// 流水号
	private String title;				// 标题
	private String content;				// 内容
	private Boolean ip;					// 是否公开信息(公告)
	private Byte type;					// 类型，暂时不知道怎样定义
	private Date ct;					// 创建时间
	private Integer cu;					// 创建人
	private Integer oc;					// 发布机构编号
	private Boolean deleted;			// 是否删除
	private Date dt;					// 删除时间
	
	private Integer ac;					// 附件数量
	private String cun;					// 创建用户姓名
	
	
	private List<MessageAnnex> anList;	// 附件数组
	

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column
	public Integer getCode() {
		return code;
	}
	@Column(length = 60)
	public String getTitle() {
		return title;
	}
	@Column(length = 10000)
	public String getContent() {
		return content;
	}
	@Column
	public Boolean getIp() {
		return ip;
	}
	@Column
	public Byte getType() {
		return type;
	}
	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false, nullable = false)
	public Date getCt() {
		return ct;
	}
	@Column
	public Integer getCu() {
		return cu;
	}
	@Column
	public Integer getOc() {
		return oc;
	}
	@Column
	public Boolean getDeleted() {
		return deleted;
	}
	@Temporal(TemporalType.TIMESTAMP)
	@Column
	public Date getDt() {
		return dt;
	}

	@Formula("(SELECT COUNT(*) FROM MessageAnnex ma WHERE ma.mc = code)")
	public Integer getAc() {
		return ac;
	}
	@Formula("(CASE cu WHEN 0 THEN '系统消息' ELSE (SELECT u.realName FROM UserInfo u WHERE u.code = cu) END)")
	public String getCun() {
		return cun;
	}
	
	@Transient
	public List<MessageAnnex> getAnList() {
		return anList;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	public void setCode(Integer code) {
		this.code = code;
	}
	public void setAnList(List<MessageAnnex> anList) {
		this.anList = anList;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public void setIp(Boolean ip) {
		this.ip = ip;
	}
	public void setType(Byte type) {
		this.type = type;
	}
	public void setCt(Date ct) {
		this.ct = ct;
	}
	public void setCu(Integer cu) {
		this.cu = cu;
	}
	public void setOc(Integer oc) {
		this.oc = oc;
	}
	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}
	public void setDt(Date dt) {
		this.dt = dt;
	}
	

	public void setAc(Integer ac) {
		this.ac = ac;
	}
	public void setCun(String cun) {
		this.cun = cun;
	}
}
